﻿using System.Collections.Generic;
using System.Xml.Linq;
using QASPRibbon.Commands;
using Schema = QASPRibbon.RibbonSchema;

namespace QASPRibbon.Controls
{
    /// <summary>
    /// Base class for all other SharePoint Ribbon controls.
    /// </summary>
    public abstract class RibbonControl : RibbonElement
    {
        /// <summary>
        /// Template alias Id
        /// </summary>
        public string TemplateAlias
        {
            get { return _templateAlias; }
            set { _templateAlias = value; }
        }

        private bool _visible = true;
        private string _templateAlias;

        /// <summary>
        /// Gets or sets a value that indicates whether a control is rendered on the ribbon.
        /// </summary>
        public bool Visible
        {
            get { return _visible; }
            set { _visible = value; }
        }

        protected RibbonControl() { }

        protected RibbonControl(string id) : base(id) { }

        protected RibbonControl(string id, string title) : base(id, title) { }

        internal override XElement AsXElement()
        {
            var element = new XElement(XmlTag);
            element.Add(new XAttribute(Schema.Id, FullId));
            if (Sequence > 0)
                element.Add(new XAttribute(Schema.Sequence, Sequence));

            return element;
        }

        internal virtual IEnumerable<RibbonCommand> ClientCommands { get; set; }
    }
}
